#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define REP(i,n) for(int i=0;i<int(n);++i)
#define FOR(i,a,n) for(int i=a;i<int(n);++i)
using namespace std;

typedef long long lld;

struct Node
{
	int key,dep;
	Node *parent,*child[2],*lEnd,*rEnd;
	lld sum;
};
Node node[100100];

int n,k;
Node *root;
vector<Node*> leaves;
bool cmp(Node *a,Node *b)
{
	return a->key<b->key;
}

Node* getEnd(Node *nt)
{
	//printf("getEnd %d\n",nt-node);
	if(!nt->child[0])
	{
		nt->lEnd=nt->rEnd=nt;
		return nt;
	}
	//printf("node[%d]: l = %d r = %d\n",nt-node,nt->child[0]-node,nt->child[1]-node);
	Node *end;
	end = getEnd(nt->child[0]);
	nt->lEnd = end;
	end = getEnd(nt->child[1]);
	nt->rEnd = end;
	if(!nt->parent) return NULL;
	if(nt->key<nt->parent->key) return nt->lEnd;
	else return nt->rEnd;
}
void getSum()
{
	queue<Node*> q;
	q.push(root);
	root->dep=0;
	while(!q.empty())
	{
		Node *nt = q.front();q.pop();
		if(!nt->child[0]) continue;
		nt->child[0]->sum = nt->sum + nt->child[1]->lEnd->key;
		nt->child[0]->dep = nt->dep+1;
		nt->child[1]->sum = nt->sum + nt->child[0]->rEnd->key;
		nt->child[1]->dep = nt->dep+1;
		q.push(nt->child[0]);
		q.push(nt->child[1]);
	}
}
double getAns(int num)
{
	int high = leaves.size()-1,low = 0;
	while(low<high)
	{
		int mid = (high+low)>>1;
		int t = leaves[mid]->key;
		if(t > num) high = mid;
		else low = mid+1;
	}
	while(leaves[low]->child[0])
	{
		low--;
	}
	//printf("pos = %d\n",leaves[low]-node);
	return (double)leaves[low]->sum/leaves[low]->dep;
}
int main()
{
	cin>>n;
	FOR(i,1,n+1)
	{
		int parent,key;
		scanf("%d%d",&parent,&key);
		node[i].key = key;
		if(parent==-1) root = &node[i];
		else node[i].parent = &node[parent];
		leaves.push_back(&node[i]);
	}
	FOR(i,1,n+1)
	{
		if(root==&node[i]) continue;
		if(node[i].key<node[i].parent->key)
			node[i].parent->child[0] = &node[i];
		else node[i].parent->child[1] = &node[i];
	}
	getEnd(root);
	getSum();
	sort(leaves.begin(),leaves.end(),cmp);
	cin>>k;
	while(k--)
	{
		int num;
		scanf("%d",&num);
		printf("%.9f\n",getAns(num));
	}
	return 0;
}
